<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="../node_modules/_swiper@6.8.4@swiper/swiper-bundle.css"
    />
    <style>
      .swiper-container,
      .swiper-wrapper,
      .swiper-slide {
        width: 100%;
      }

      .swiper-slide {
        display: flex;
        align-items: flex-start;
        justify-content: space-around;
        flex-wrap: wrap;
        margin-top: 3rem;
      }
      /*切换按钮样式*/
      .tab {
        width: 100%;
        height: 50px;
        overflow: hidden;
        border-bottom: 1px solid #eee;
        position: fixed;
        top: 2.5rem;
        left: 0;
        z-index: 999;
        background-color: #fff;
      }

      .tabItem {
        width: 20%;
        height: 50px;
        float: left;
        background: #fff;
        line-height: 50px;
        text-align: center;
      }
      /*切换按钮点击样式*/
      .active {
        height: 50px;
        border-bottom: 3px solid #fe2d26;
        box-sizing: border-box;
      }
    </style>
  </head>
  <body>
    <body>
      <div class="tab">
        <div class="tabItem active">全部</div>
        <div class="tabItem">待付款</div>
        <div class="tabItem">待发货</div>
        <div class="tabItem">待收货</div>
        <div class="tabItem">待评价</div>
      </div>
      <script src="../node_modules/_jquery@3.6.0@jquery/dist/jquery.js"></script>
      <script src="../node_modules/_swiper@6.8.4@swiper/swiper-bundle.min.js"></script>
      <script>
        var tabItem = $(".tab .tabItem");
        var mySwiper = new Swiper(".swiper-container", {
          autoplay: false,
        //   on: {
        //     //swiper从当前slide开始过渡到另一个slide时执行
        //     slideChangeTransitionStart: function () {
        //       //过渡后的slide索引
        //       var n = this.activeIndex;
        //       changeTab(n);
        //       // 切换的内容回到顶部
        //       $("html,body").animate({ scrollTop: 0 }, 10);
        //     },
        //   },
        });

        

        //tab点击切换silde
        tabItem.click(function () {
          var ind = $(this).index();
          changeTab(ind);
          mySwiper.slideTo(ind);
        });
        //tab切换样式
        function changeTab(index) {
          tabItem.removeClass("active").eq(index).addClass("active");
        }
      </script>
    </body>
  </body>
</html>
